import { debounce } from './utils'
import BackTop from "components/content/backTop/BackTop";


export const itemListenerMixin = {
  data() {
    return {
      itemImgListener: null
      // refresh: null 还可将防抖函数保存在data中，这样引入mixin的组件就可在任意位置使用防抖函数了
    }
  },
  mounted() {
    const refresh = debounce(this.$refs.scroll.refresh, 0)
    this.itemImgListener = () => { refresh() }
    this.$bus.$on('itemImageLoad', this.itemImgListener)
    console.log('I am in mixins');
  }
}

export const backTopMixin = {

  data() {
    return {
      isShowBackTop: false,
    }
  },
  components: {
    BackTop
  },
  methods: {
    listenerBackTop(position) {
      this.isShowBackTop = -position.y > 1000 ? true : false;
    },
    goTop() {
      this.$refs.scroll.scrollTo(0, 0, 500);
    },
  },
}